package SceneTrigger

import (
	//"fmt"
	"misc/Clojure"
	. "misc/Clojure/parse"
)

type ITriggerAction interface {
	OnExec(*Clojure.Context)
	Update()
	GetType() int
	GetActionInfo() *TriggerActionInfo
}

const (
	TriggerAction_Block    = 0
	TriggerAction_NonBlock = 1
)

type TriggerActionInfo struct {
	ActionNode Node
	CurTrigger *Trigger
	Typ        int
}

func (this *TriggerActionInfo) GetType() int {
	return this.Typ
}

type IBlockTrigerAction interface {
	GetType() int
	OnExec(*Clojure.Context)
	OnExit()
	Update()
	IsFinish() bool
	GetActionInfo() *TriggerActionInfo
}

type NonBlockAction struct {
	TriggerActionInfo
}

func NewNonBlockAction(node Node) *NonBlockAction {
	action := &NonBlockAction{}
	action.ActionNode = node
	action.Typ = TriggerAction_NonBlock
	return action
}

func (this *NonBlockAction) OnExec(context *Clojure.Context) {
	Clojure.Evaluate(this.ActionNode, context)
}
func (this *NonBlockAction) Update() {

}
func (this *NonBlockAction) GetActionInfo() *TriggerActionInfo {
	return &this.TriggerActionInfo
}

//BlockActions
///////////////////////////////////////////////////////
type blockActionNewFunc func([]Node) IBlockTrigerAction

var blockActions map[string]blockActionNewFunc

func initblockActionFuncs() {
	blockActions = make(map[string]blockActionNewFunc)
	blockActions["wait"] = NewWaitAction
}

func GetBlockActionNewFunc(actionName string) blockActionNewFunc {
	return blockActions[actionName]
}
